<?php
class SiteSetting extends AppModel {
	var $name = 'SiteSetting';
	var $displayField = 'var';
	var $validate = array(
		'var' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'value' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'section' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'type' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
	);
    
    function getAll($fullData=false)
    {
        $settings = array();
        $records = $this->find('all',array('order'=>'SiteSetting.section'));
		if($fullData==true) return $records;
        foreach($records as $record)
        {
            $settings[$record['SiteSetting']['var']] = $record['SiteSetting']['value']; 
        }
        
        return $settings;
    }
	
	function updateVar($var,$val)
	{
		return $this->updateAll(array('SiteSetting.value'=>'"'.$val.'"'),array('SiteSetting.var'=>$var));	
	}
}
